---
title: 'Camera picker dialog'
sidebarTitle: 'Camera picker'
description: 'Open a camera picker dialog in a Kotlin Multiplatform project'
---

import AndroidFileProviderSetup from '/snippets/android-fileprovider-setup.mdx'

<Check>Supported on Android and iOS targets</Check>

## Quick start

The camera picker component provides a native interface for users to capture photos using their device's camera.

<CodeGroup>
```kotlin filekit-dialogs
val file = FileKit.openCameraPicker()
```

```kotlin filekit-dialogs-compose
val launcher = rememberCameraPickerLauncher { file ->
    // Handle the captured photo
}

Button(onClick = { launcher.launch() }) {
    Text("Take a photo")
}
```
</CodeGroup>

The captured media file is automatically saved to the specified location (or cache directory by default). If you need to keep the file permanently, make sure to copy it to a permanent storage location.

## Camera type

You can specify the type of media to capture using the `type` parameter:
- `Photo` - Capture a photo (default)
- `Video` - Capture a video (coming soon)

<CodeGroup>
```kotlin filekit-dialogs
val file = FileKit.openCameraPicker(type = FileKitCameraType.Photo)
```

```kotlin filekit-dialogs-compose
val launcher = rememberCameraPickerLauncher { file ->
    // Handle the captured photo
}

Button(onClick = { launcher.launch(type = FileKitCameraType.Photo) }) {
    Text("Take a photo")
}
```
</CodeGroup>

<Info>
Video capture support is planned for a future release.
</Info>

## Camera facing

You can specify whether the front or rear facing camera is used, using the `cameraFacing` parameter:
- `Front` opens the front facing camera (Selfie-Camera)
- `Back` opens the rear facing camera

By default, the rear facing camera is used.

<CodeGroup>
```kotlin filekit-dialogs
val file = FileKit.openCameraPicker(cameraFacing = FileKitCameraFacing.Front)
```

```kotlin filekit-dialogs-compose
val launcher = rememberCameraPickerLauncher { file ->
    // Handle the captured photo
}

Button(onClick = { launcher.launch(cameraFacing = FileKitCameraFacing.Front) }) {
    Text("Take a selfie")
}
```
</CodeGroup>

<Warning>
Android has no documented parameter for an intent to specify which camera is supposed to be used by the Camera App.
Since Android implementations differ, we can not guarantee that this feature will work for every device/Android version.
If you encounter issues please file an issue.
</Warning>

## Destination file

You can specify where the captured photo should be saved using the `destinationFile` parameter. By default, the photo is saved to the cache directory with a randomly generated filename.

<CodeGroup>
```kotlin filekit-dialogs
// Using default destination (cache directory with random filename)
val file = FileKit.openCameraPicker()

// Specifying a custom destination
val customFile = FileKit.filesDir / "my_photo.jpg"
val file = FileKit.openCameraPicker(destinationFile = customFile)
```

```kotlin filekit-dialogs-compose
val launcher = rememberCameraPickerLauncher { file ->
    // Handle the captured photo
}

// Using default destination
Button(onClick = { launcher.launch() }) {
    Text("Take a photo")
}

// Specifying a custom destination
val customFile = FileKit.filesDir / "my_photo.jpg"
Button(onClick = { launcher.launch(destinationFile = customFile) }) {
    Text("Take a photo to custom location")
}
```
</CodeGroup>

<Warning>
On Android, when using a custom `destinationFile`, you must provide the `openCameraSettings` parameter with your app's FileProvider authority. This ensures the camera app has permission to write to your specified location.
</Warning>

## Destination file Android Setup

<AndroidFileProviderSetup />

3. When using a custom `destinationFile`, provide the `openCameraSettings` parameter with your app's FileProvider authority:

<CodeGroup>
```kotlin filekit-dialogs
val customFile = FileKit.filesDir / "my_photo.jpg"
val file = FileKit.openCameraPicker(
    destinationFile = customFile,
    openCameraSettings = FileKitOpenCameraSettings(
        authority = "${context.packageName}.fileprovider"
    )
)
```

```kotlin filekit-dialogs-compose
val customFile = FileKit.filesDir / "my_photo.jpg"
Button(onClick = { 
    launcher.launch(
        destinationFile = customFile,
        openCameraSettings = FileKitOpenCameraSettings(
            authority = "${context.packageName}.fileprovider"
        )
    )
}) {
    Text("Take a photo to custom location")
}
```
</CodeGroup>
